<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">出借方</label>
                        <div class="layui-input-block">
                            <input type="text" name="chuer" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">借款人</label>
                        <div class="layui-input-block">
                            <input type="text" name="jieer" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">合同编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">放款到账日期</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="daodt" placeholder="请输入" autocomplete="off" class="layui-input bdate_sea_range_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">审核状态：</label>
                        <div class="layui-input-block">
                            <select id="status" name="status" lay-filter="status">
                                <option value="">请选择</option>
                                <option value="1">流程（审批通过）</option>
                                <option value="0">流程（审批中）</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>


<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_show('查看','{{d.LAY_TABLE_INDEX}}')">查看</a>
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script>


    var param_jieid = getQueryVariable('jieid') || 0;
    var currButAuth, currTabData;
    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;


        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        var height_l = $('.laytp-container').height() - 140;
        $('#tree_content').css('cssText','height:'+height_l+'px');
        $('.engindao_bac').css('cssText','height:'+height_l+'px');

        setSouTableExport('借款收条');
        table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_hou_tiao_list)
            ,where: {jieid:param_jieid}
            , page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response
            ,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text,totalRow: true
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{type:'numbers',title:'序号',totalRowText: '合计',fixed:'left'}
                ,list_bill_cols_str
                ,{field:'statename',title:'借款状态',templet: function(d){
                    if(d.statename == '未还款'){
                        return '<span class="colorhong">'+d.statename+'</span>';
                    }else if(d.statename == '已还款'){
                        return '<span class="colorlv">'+d.statename+'</span>';
                    }else{
                        return d.statename;
                    }
                }}
                ,{field: 'number', title: '合同编号'}
                ,{field: 'jieer', title: '借款人'}
                ,{field: 'chuer', title: '出借方'}
                ,{field:'jiemoney',title:'借款金额(元)',templet: function(d){return parseFormatNum(d.jiemoney);}}
                ,{field:'fangfee',title:'放款金额合计(元)',templet: function(d){return parseFormatNum(d.fangfee);}}
                ,{field:'money',title:'本次放款金额(元)',totalRow: true,templet: function(d){return parseFormatNum(d.money);}}
                ,{field: 'daodt', title: '放款日期'}
                ,{field: 'tianshu', title: '天数'}
                ,{field: 'yueshu_zhan', title: '借款周期数'}
                ,{field: 'yuerate', title: '周期利率'}

                ,{field:'yinghuanbenfee',title:'应还本金(元)',totalRow: true,templet: function(d){return parseFormatNum(d.yinghuanbenfee);}}
                ,{field:'yinghuanlifee',title:'应还利息(元)',totalRow: true,templet: function(d){return parseFormatNum(d.yinghuanlifee);}}
                ,{field:'yinghuanallfee',title:'应还合计(元)',totalRow: true,templet: function(d){return parseFormatNum(d.yinghuanallfee);}}

                ,{field:'yihuanbenfee',title:'已还本金(元)',totalRow: true,templet: function(d){return parseFormatNum(d.yihuanbenfee);}}
                ,{field:'yihuanlifee',title:'已还利息(元)',totalRow: true,templet: function(d){return parseFormatNum(d.yihuanlifee);}}
                ,{field:'yihuanallfee',title:'已还合计(元)',totalRow: true,templet: function(d){
                        return '<span class="colorlan" onclick="openNavPage(\'扣收借款（含利息）明细\',\'hou_chi_kou_gongjie/index.php?tiaoid='+d.id+'\')">'+parseFormatNum(d.yihuanallfee)+'</span>';
                    }}

                ,{field:'lixiyoufee',title:'利息优惠(元)',totalRow: true,templet: function(d){return parseFormatNum(d.lixiyoufee);}}

                ,{field:'daihuanbenfee',title:'待还本金(元)',totalRow: true,templet: function(d){return parseFormatNum(d.daihuanbenfee);}}
                ,{field:'daihuanlifee',title:'待还利息(元)',totalRow: true,templet: function(d){return parseFormatNum(d.daihuanlifee);}}
                ,{field:'daihuanallfee',title:'待还合计(元)',totalRow: true,templet: function(d){return parseFormatNum(d.daihuanallfee);}}
                ,{fixed: 'right', title:'操作', toolbar: '#test-dropdown-toolbar-barDemo',align:'center',width:200}
            ]]
            , done: function (res) {
                soulTable.render(this);

                currTabData = res.data;
                $.each(currTabData, function(index,item){
                    var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                    for (var key in currButAuth) {
                        if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1){
                            if(currTabData[index].status != 1){
                                continue;
                            }
                            chk.append(' <a ' +
                                'href="javascript:;" ' +
                                'class="bar_opt layui-hide" ' +
                                'lay-event="search" ' +
                                'data-butname="'+currButAuth[key].butname+'" ' +
                                'data-title="'+currButAuth[key].title+'" ' +
                                'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                                '>'+currButAuth[key].title+'' +
                                '</a>');
                        }
                    }
                });
                show_tab_but(currTabData);
            }
        });

        listTableSearch(form, table);

    });


    function auth_but_func_show(buttitle, index){
        var trData = currTabData[index];
        openPage('show.php?id='+trData.id);
    }
    function auth_but_func_add(){
        openPageEdit('add.php?close=1');
    }
    function auth_but_func_add_flow(){
        openPageEdit('flow_add.php?close=1');
    }
    function auth_but_func_edit(buttitle, index){
        var trData = currTabData[index];
        openPageEdit('edit.php?close=1&id='+trData.id);
    }
    function auth_but_func_delete(buttitle, index){
        var trData = currTabData[index];
        data_delete(ask_hou_tiao_del, {id:trData.id});
    }

    function opt_tree(data, status) {
        for (var i=0;i<data.length;i++){
            data[i]['spread'] = status;
            if(data[i].children != undefined){
                opt_tree(data[i].children, status);
            }
        }
        return data;
    }
</script>
</body>
</html>
